#ifndef DEMUXMEDIA_H
#define DEMUXMEDIA_H

extern "C"{
#include <libavformat/avformat.h>
}

/**
 * @brief The Demux class 解复用
 */
class DemuxMedia
{
public:
    DemuxMedia();
    ~DemuxMedia();

public:
    bool openMediaStream(const char* url);
    AVPacket* readPacket();
    int getAudioIndex();
    int getVideoIndex();
    AVCodecParameters* copyAVCodecParams(int streamIndex);
    double r2d(AVRational r)
    {
        return r.den == 0 ? 0 : (double)r.num / (double)r.den;
    }

private:
    AVFormatContext* avFmtCtx = nullptr;
    int audioIndex = -1;
    int videoIndex = -1;
};

#endif // DEMUXMEDIA_H
